import request from "@/util/request";
import type {IngredientsSearchParam, Ingredients} from "./types";
import type {Page} from "@/api/page/types";

const API: string = '/dishes-service/ingredients'

/**
 * 查询接口
 */
export const getIngredientsList = (form: IngredientsSearchParam) => {
    return request<Page<Ingredients>, Page<Ingredients>>({
        url: API + '/list',
        method: "GET",
        params: form
    })
}

/**
 * 添加接口
 */
export const addIngredients = (form: Ingredients) => {
    return request<any, any, Ingredients>({
        url: API,
        method: 'post',
        data: form
    })
}

/**
 * 更新接口
 */
export const updateIngredients = (id: number, form: Ingredients) => {
    return request<any, any, Ingredients>({
        url: `${API}/${id}`,
        method: 'put',
        data: form
    })
}

/**
 * 删除接口
 */
export const deleteIngredients = (id: number) => {
    return request<any, any>({
        url: `${API}/${id}`,
        method: 'delete'
    })
}

/**
 * 根据食材类型查询食材
 */
export const getIngredientsByType = (type: string) => {
    return request<Ingredients[], Ingredients[]>({
        url: API + '/listByType?type=' + type,
        method: 'get'
    })
}